package org.simple.spring.ssm.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.simple.spring.ssm.entity.Category;
import org.simple.spring.ssm.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 项目名称：spring-leaning
 * 类名称：IndexController
 * 类描述：IndexController
 * 创建时间：2018/8/7
 *
 * @author guihuo   (E-mail:1620657419@qq.com)
 * @version v1.0
 */
@Controller
public class IndexController {

    private final Log logger = LogFactory.getLog(this.getClass());

    @Autowired
    private CategoryService categoryService;

    @RequestMapping()
    public String index(Model mv) {
        mv.addAttribute("message", "Hello World！");
        return "welcome";
    }

    @RequestMapping("/listCategory")
    public ModelAndView listCategory() {
        ModelAndView mav = new ModelAndView();
        List<Category> cs = categoryService.list();
        // 放入转发参数
        mav.addObject("cs", cs);
        // 放入jsp路径
        mav.setViewName("category");
        return mav;
    }


}
